package view;

import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import controller.CreateNewDiagramController;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class CreateNewDiagramView extends View<CreateNewDiagramController> implements Displayable{

	private static CreateNewDiagramView instance = null;
	
	private CreateNewDiagramController controller;
	private JFrame frame;
	private JTextField textField;

	/**
	 * Create the application.
	 */
	private CreateNewDiagramView() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		setFrame(new JFrame("Crear proyecto"));
		getFrame().setBounds(100, 100, 450, 300);
		getFrame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		getFrame().getContentPane().setLayout(null);

		JButton btnCrearProyecto = new JButton("Aceptar");
		btnCrearProyecto.setBounds(76, 168, 140, 25);
		btnCrearProyecto.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				getController().handleButtonAceptar();
			}
		});
		getFrame().getContentPane().add(btnCrearProyecto);

		JButton btnAbrirProyecto = new JButton("Cancelar");
		btnAbrirProyecto.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				getController().handleButtonCancelar();
			}
		});
		btnAbrirProyecto.setBounds(228, 168, 146, 25);
		getFrame().getContentPane().add(btnAbrirProyecto);

		textField = new JTextField();
		textField.setBounds(76, 40, 301, 19);
		getFrame().getContentPane().add(textField);
		textField.setColumns(10);

		JLabel lblNewLabel = new JLabel("Ingrese nombre del nuevo proyecto");
		lblNewLabel.setFont(new Font("DejaVu Sans", Font.BOLD, 16));
		lblNewLabel.setBounds(60, 84, 333, 15);
		getFrame().getContentPane().add(lblNewLabel);
	}

	@Override
	public void show() {
		getInstance().getFrame().setVisible(true);
	}

	@Override
	public void hide() {
		getInstance().getFrame().setVisible(false);
	}

	public static CreateNewDiagramView getInstance(){
		if (instance == null){
			instance = new CreateNewDiagramView();
		}
		return instance;
	}

	public JFrame getFrame() {
		return frame;
	}

	public void setFrame(JFrame frame) {
		this.frame = frame;
	}
	
	public String getDiagramName(){
		return this.textField.getText();
	}

	@Override
	public CreateNewDiagramController getController() {
		return this.controller;
	}

	@Override
	public void setController(CreateNewDiagramController controller) {
		this.controller = controller;
	}
}
